package dfs_bfs.test17;

import java.util.*;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/9 8:25
 */
public class Solution2 {

    // 方法二 ： 使用一个队列来维持循环
    public List<String> letterCombinations(String digits) {
        if (digits == null || digits.length() == 0) return new ArrayList<>();
        String[] dic = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        ArrayDeque<String> res = new ArrayDeque<>();
        res.addFirst("");
        for (int i = 0; i < digits.length(); i++) {
            char[] temps = dic[digits.charAt(i) - '2'].toCharArray();
            int size = res.size();
            for (int j = 0; j < size; j++) {
                String s = res.pollFirst();
                for (char c : temps) {
                    res.addLast(s + c);
                }
            }
        }
        return new ArrayList<>(res);
    }
}
